﻿using UnityEngine;
using System.Collections;
using ProtoBuf.Message;
using System.Collections.Generic;

namespace UI
{
    public class RushFightReadyPage : Page
    {
        public UILabel currentFloorLabel;
        public UILabel winConditionLabel;

        public RushFightReadyItem easyItem;
        public RushFightReadyItem normalItem;
        public RushFightReadyItem hardItem;

        public List<UITweener> tweeners;


        protected override void DoOpen()
        {
            currentFloorLabel.text = string.Format(TableTextBlo.GetText("di_x_ceng"), StaticData.rushCurFloorNum);
            winConditionLabel.text = RushPage.ParseWinCondition(StaticData.rushCurWinKey, StaticData.rushCurWinValue);

            CSRushCurrentInfo info = new CSRushCurrentInfo();
            NetAPI.SendHttp(OpDefine.CSRushCurrentInfo, info, (pack, b) => {
                if (b) {
                    SCRushCurrentInfo msg = pack.kBody as SCRushCurrentInfo;
                    Refresh(msg);
                }
            });

            foreach (var tweener in tweeners) {
                if (tweener != null) {
                    tweener.ResetToBeginning();
                    tweener.PlayForward();
                }
            }
        }

        protected override void DoClose()
        {
            easyItem.Hide();
            normalItem.Hide();
            hardItem.Hide();
        }

        void Refresh(SCRushCurrentInfo msg) {
            easyItem.Hide();
            normalItem.Hide();
            hardItem.Hide();
            foreach (var info in msg.taskInfoList) {
                if (info.star == 1)
                {
                    easyItem.Init(info, this);
                }
                else if (info.star == 2)
                {
                    normalItem.Init(info, this);
                }
                else if (info.star == 3)
                {
                    hardItem.Init(info, this);
                }
            }
        }

    }

}